<?php

if (!defined('easyframework_inited')) 
	exit('No direct script access allowed');
    
/**
 *  @file test.php
 *  @brief Testing the easyinireaderwriter class
 *  @author Vajay Attila
 *  @email vajay.attila@gmail.com
 *  @date 2014-07-28
 *  @copyright MIT License (MIT)
 */

require_once 'helpers/html.php';
require_once 'libraries/easyinireaderwriter.php';
 
function dotest(){
	echohtmlbegin();
	echoheader();
	echobodybegin();

	echo 'test.php loaded...<br>'."\r\n";
    $eirw = new easyinireaderwriter();
    $eirw2 = new easyinireaderwriter();	
    echo 'loaded library: '.$eirw->getlibraryname().' ('.$eirw->getversion().') <br>'."\r\n";
    
	setloglevel(LOGGER_DEBUG);
	log_message(LOGGER_INFO, 'Testing load INI file begin ---------------------------------------------------');					
    $eirw->loadinifile('test/testinput.ini');
	echo 'add \'GENERATED_BY_TEST\' section. return value: '.($eirw->addsection('GENERATED_BY_TEST')==TRUE?'true':'false').'<br>';
	echo 'add \'GENERATED_BY_TEST\' section. return value: '.($eirw->addsection('GENERATED_BY_TEST')==TRUE?'true':'false').'<br>';	
	echo 'add \'GENERATED_LABEL\' label in \'GENERATED_BY_TEST\' section. return value: '.($eirw->addlabel('GENERATED_BY_TEST', 'GENERATED_LABEL')==TRUE?'true':'false').'<br>';		
	echo 'add \'GENERATED_LABEL\' label in \'GENERATED_BY_TEST\' section. return value: '.($eirw->addlabel('GENERATED_BY_TEST', 'GENERATED_LABEL')==TRUE?'true':'false').'<br>';		
	echo 'add \'GENERATED_LABEL2\' label in \'GENERATED_BY_TEST\' section. return value: '.($eirw->addlabel('GENERATED_BY_TEST', 'GENERATED_LABEL2')==TRUE?'true':'false').'<br>';		
	$retval=$eirw->setvalue('GENERATED_BY_TEST', 'GENERATED_LABEL', 'value');
	echo 'set value of \'GENERATED_BY_TEST\' section and \'GENERATED_LABEL\' label.return value:'.($retval===FALSE?'false':'\''.$retval.'\'').'<br>';	
	$retval=$eirw->setvalue('GENERATED_BY_TEST', 'GENERATED_LABEL', 'value1');
	echo 'set value of \'GENERATED_BY_TEST\' section and \'GENERATED_LABEL\' label.return value:'.($retval===FALSE?'false':'\''.$retval.'\'').'<br>';	
	$retval=$eirw->setvalue('GENERATED_BY_TEST', 'GENERATED_LABEL2', 'value2');
	echo 'set value of \'GENERATED_BY_TEST\' section and \'GENERATED_LABEL\' label.return value:'.($retval===FALSE?'false':'\''.$retval.'\'').'<br>';	
	$retval=$eirw->setvalue('GENERATED_BY_TEST', 'UNKNOWN', 'value2');
	echo 'set value of \'GENERATED_BY_TEST\' section and \'UNKNOWN\' label.return value:'.($retval===FALSE?'false':'\''.$retval.'\'').'<br>';	
	

	$sections=array();
	echo 'detected section count: '.$eirw->getsectionnames($sections).'<br>';
	echo 'the section names:<br>';
	foreach($sections as $section)
	{
		echo "'".$section."'<br>";
	}

	foreach($sections as $section)
	{
		$labels=array();
		echo "detected labels in section '".$section."'. found ".$eirw->getlabelsbysection($section, $labels)." label<br>";
		foreach($labels as $label){
			echo "'".$label."'<br>";			
		}
	}
	
	$labels=array();
	$retval=$eirw->getlabelsbysection('xxxx', $labels);
	echo 'test finding unknown section\'s labels. the \'xxxx\' section result is '.($retval===FALSE?'false':$retval).'<br>';
	
	echo 'get values:<br>';
	foreach($sections as $section)
	{
		$labels=array();
		$eirw->getlabelsbysection($section, $labels);
		foreach($labels as $label){
			echo 'section=\''.$section.'\' label=\''.$label.'\' value=\''.$eirw->getvalue($section, $label).'\'<br>';
		}
	}
	
	log_message(LOGGER_INFO, 'Testing load INI file end -----------------------------------------------------');						
        echo 'Writing inifile returned: '. ($eirw->writeinifile('test.ini', 1)===TRUE?'true':'false') .'<br>';
        
	echobodyend();	
	echohtmlend();
        
        
        
}
  

 ?>